import ctypes
from zauxdllPython import ZAUXDLL
from ErrorCode import ErrorCodes  # 假设 ErrorCodes 模块在 zauxdllPython 中


class MotorController:
    def __init__(self, ip_address):
        self.zauxdll_obj = ZAUXDLL()
        self.ip_address = ip_address
        self.ret_code = self.zauxdll_obj.ZAux_OpenEth(ip_address)
        if self.ret_code != 0:
            print(f"连接到控制器失败，错误码：{self.ret_code}")

    def move_motor(self, steps, speed):
        if self.ret_code == 0:
            command = f"MOV {steps} {speed}"
            ret, rev = self.zauxdll_obj.ZAux_DirectCommand(command)
            if ret != 0:
                error_message = ErrorCodes.get_error_message(ret)  # 假设 get_error_message 是静态方法
                print(f"发送命令失败，错误码：{ret}，错误信息：{error_message}")
            else:
                print(f"命令执行成功：{rev}")
        else:
            print("控制器未连接，无法发送命令")


# 使用示例
controller = MotorController('192.168.100.110')
controller.move_motor(1000, 500)  # 控制电机旋转1000步，速度为500
